//
//  HotCommentView.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/12.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "HotCommentView.h"
#import "ChannelCellFrameViewModel.h"
#import "ChannelContent.h"
#import "ChannelOfChannel.h"
#import "ChannelHotComment.h"
#import "HotCommentTableViewCell.h"
@interface HotCommentView ()
<
    UITableViewDelegate,
    UITableViewDataSource
>

@property (nonatomic, strong) UITableView *hotCommentTableView;

@end


@implementation HotCommentView
- (instancetype) initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // 添加所有子控件的方法
        [self setUpAllChildViews];
        
    }
    return self;
}


// 添加所有子控件的方法
- (void)setUpAllChildViews {
    
    self.hotCommentTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _hotCommentTableView.backgroundColor = [UIColor whiteColor];
    _hotCommentTableView.delegate = self;
    _hotCommentTableView.dataSource = self;
    [self addSubview:_hotCommentTableView];
    
//    [_hotCommentTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
    [_hotCommentTableView registerNib:[UINib nibWithNibName:@"HotCommentTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HotCommentTableViewCellReuse"];
    _hotCommentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _hotCommentTableView.scrollEnabled = NO;

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  _channelCellFrame.hotCommentCellHeight;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _channelCellFrame.channelContent.hotComments.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HotCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HotCommentTableViewCellReuse"];
    cell.hotComment = _channelCellFrame.channelContent.hotComments[indexPath.row];
    return cell;
    
    
}


- (void)setChannelCellFrame:(ChannelCellFrameViewModel *)channelCellFrame {
    _channelCellFrame = channelCellFrame;
    _hotCommentTableView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    [_hotCommentTableView reloadData];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
